package com.example.demo.service;

import com.example.demo.entity.Item;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;


/**
 * @Description 接口需要继承Es指定的接口，之后可以进行es的CRUD操作
 * @Author lililiang
 * @Date 09:27 21/03/02
 * @Param
 * @return
 **/
public interface ItemService extends ElasticsearchRepository<Item, String> {


    List<Item> findByPriceBetween(double price1, double price2);

    List<Item> findByTitle(String title);

    List<Item> findByTitleAndCategory(String title, String category);


    @Query("{\"bool\":{\"must\":{\"term\":{\"title.keyword\":\"?0\"}}}}")
    List<Item> getInfo(String title);

    @Query("{\"bool\":{\"must\":[{\"term\":{\"title.keyword\":\"小米手机1\"}},{\"term\":{\"brand.keyword\":\"小米\"}}]}}")
    List<Item> getInfo2(String title, String brand);
}
